package com.leyou.service;

import com.leyou.common.exception.LyException;
import com.leyou.domain.Role;
import com.leyou.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
@Transactional
public class RoleService {

    @Autowired
    private RoleMapper roleMapper;


    public List<Role> queryRoles() {
        List<Role> roles = roleMapper.selectAll();
        if (CollectionUtils.isEmpty(roles)){
            throw new LyException(502, "角色找不到！");
        }
        return roles;
    }

    public List<Role> findRoles(Long uid) {
        List<Role> roles = roleMapper.findByUid(uid);
        return roles;
    }
}
